<script setup lang="ts">
import { useRouter } from 'vue-router'
const router = useRouter()

const emit = defineEmits<{
  (e: 'click-right'): void
}>()

// 点击左箭头
const onClickLeft = () => {
  if (props.back) {
    props.back()
  } else {
    // 返回上一页
    router.back()
  }
}
// 点击右侧文字按钮
const onClickRight = () => {
  // 触发自定义事件
  emit('click-right')
}

const props = defineProps<{
  title?: string
  rightText?: string
  back?(): void
}>()
</script>

<template>
  <van-nav-bar
    :title="title"
    :right-text="rightText"
    left-arrow
    @click-left="onClickLeft"
    @click-right="onClickRight"
  />
</template>

<style lang="scss" scoped>
::v-deep() {
  .van-nav-bar__arrow {
    font-size: 18px;
    color: var(--cp-text1);
  }
  .van-nav-bar__text {
    font-size: 15px;
  }
}
</style>
